package com.cn.wanxi.dao.impl;

import com.cn.wanxi.dao.ICompanyDao;
import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.util.JDBC;

import java.sql.ResultSet;
import java.sql.SQLException;

public class CompanyImpl implements ICompanyDao {
    /**
     * 数据实现层
     * 1.封装sql
     * 2.封装从数据库得到的数据
     * 3.返回结果
     *
     * @return
     */
    @Override
    public CompanyModel getCompanyModel() {
        String sql = "select * from tab_company";
        ResultSet resultSet = JDBC.getResultSet(sql);
        CompanyModel companyModel = new CompanyModel();
        try {
            while (resultSet.next()) {
//                companyModel = new CompanyModel();
                companyModel.setLogo(resultSet.getString("logo"));
                companyModel.setAd(resultSet.getString("ad"));
                companyModel.setPhone(resultSet.getString("phone"));
                companyModel.setNet(resultSet.getString("net"));
                companyModel.setEmail(resultSet.getString("email"));
                companyModel.setLinePhone(resultSet.getString("line_phone"));
                companyModel.setAddress(resultSet.getString("address"));
                companyModel.setVersion(resultSet.getString("version"));
                companyModel.setContent(resultSet.getString("content"));
                companyModel.setId(resultSet.getInt("id"));

            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return companyModel;
    }
}
